ARG PYTHON_VERSION=3.9
FROM python:${PYTHON_VERSION}-bullseye


ENV TIMEZONE=Asia/Shanghai \
    DEBIAN_FRONTEND=noninteractive \
    S6_OVERLAY_VERSION=3.2.0.2


RUN set -eux ; \
    sed -i 's@deb.debian.org@mirrors.aliyun.com@g' /etc/apt/sources.list ; \
    sed -i 's@security.debian.org@mirrors.aliyun.com@g' /etc/apt/sources.list ; \
    apt update ; \
    apt-get install -y locales ; \
    localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 && \
    apt-get install -y --no-install-recommends \
        apt-transport-https \
        apt-utils \
        acl \
        aptitude \
        bash \
        busybox-static \
        ca-certificates \
        curl \
        dirmngr \
        dos2unix \
        fail2ban \
        gettext \
        gnupg \
        git \
        inetutils-ping \
        iptables \
        jq \
        less \
        libpcre3 \
        libyaml-0-2 \
        logrotate \
        msmtp \
        nano \
        net-tools \
        netcat-openbsd \
        procps \
        sudo \
        tzdata \
        xz-utils \
        vim-tiny \
        psmisc \
        python3-jinja2 \
        openssh-server \
        zstd ; \
        \
        \
    mv /usr/bin/envsubst /usr/local/bin/ ; \
    rm -rf /usr/bin/crontab /usr/sbin/cron ; \
    \
    echo "link busybox to commands" ; \
    ln -s /bin/busybox /usr/sbin/crond ; \
    ln -s /bin/busybox /usr/sbin/crontab ; \
    \
    echo "set timezone to ${TIMEZONE}"; \
    rm -rf /etc/timezone ; \
    ln -sfnv /usr/share/zoneinfo/Asia/Shanghai /etc/localtime ; \
    echo "${TIMEZONE}" > /etc/timezone ; \
    dpkg-reconfigure -f noninteractive tzdata ; \
    \
    echo "Install S6"; \
    ARCHIVE_TMP_DIR=$(mktemp -d) ; \
    cd $ARCHIVE_TMP_DIR ; \
    curl -sSLf -o s6-overlay-noarch.tar.xz https://github.com/just-containers/s6-overlay/releases/download/v3.2.0.2/s6-overlay-noarch.tar.xz ; \
    tar -p -xf s6-overlay-noarch.tar.xz --strip-components=1 -C / ; \
    \
    curl  -sSLf -o s6-overlay-x86_64.tar.xz https://github.com/just-containers/s6-overlay/releases/download/v3.2.0.2/s6-overlay-x86_64.tar.xz ; \
    tar -p -xf s6-overlay-x86_64.tar.xz --strip-components=1 -C / ; \
    \
    \
    rm -rf $ARCHIVE_TMP_DIR ; \
    \
    \
    echo "clean up" ; \
    apt purge -y gettext; \
    apt autoremove -y ; \
    apt clean -y ; \
    rm -rf \
         /etc/logrotate.d/* \
         /root/.cache \
         /root/.gnupg \
         /usr/share/doc/* \
         /usr/share/gnome/help/* \
         /usr/share/info/* \
         /usr/share/linda/* \
         /usr/share/locale/* \
         /usr/share/man/* \
         /usr/share/omf/*/*-*.emf \
         /usr/src/* \
         /var/lib/apt/lists/* \
         /var/log/*  \
         /tmp/* \
         /var/tmp/* 



RUN pip config set global.index-url https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple ; \ 
    pip install jinja2

SHELL ["/bin/bash", "-c"]

COPY rootfs /
RUN chmod +x  /etc/cont-init.d/*

#STOPSIGNAL SIGQUIT
ENTRYPOINT ["/init"]


CMD ["sleep", "infinity"]
